<template>
  <page-meta :root-font-size="$rootFontSize"></page-meta>
  <view style="min-height: 100vh" class="bg-gray">
    <u-loading-page
      :loading="isLoading"
      loading-mode="spinner"
      icon-size="56rpx"
      loading-text="拼命加载中..."
      fontSize="28rpx"
      class="z-50 top-0"
    ></u-loading-page>
    <!--钱包-->
    <view class="mx-4">
      <view class="bg-white rounded-2xl py-2.5 bg-box-shadow">
        <view class="mx-3.5">
          <view class="text-base text-dark leading-8">余额</view>
          <view class="pt-2 pb-4"
            ><text class="text-darkNormal text-2xl mr-1">￥</text
            ><text class="text-4xl font-semibold text-dark"
              >{{ userData.accountBalance }}
            </text></view
          >
        </view>
      </view>
      <view class="flex mt-6">
        <view class="flex w-1/2 h-40 rounded-2xl bg-white mr-2">
          <view
            class="self-center text-center w-full text-xl text-dark"
            @click="goTo('bill')"
            >明细</view
          >
        </view>
        <view
          class="flex w-1/2 h-40 rounded-2xl bg-primary common-box-shadow ml-2"
        >
          <view
            class="self-center text-center w-full text-xl text-white"
            @click="goToCash('withdraw')"
            >提现</view
          >
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { getWalletInfo, withdrawalCheck } from '../../services/mine';

export default {
  data() {
    return {
      isLoading: false,
      userData: {
        accountBalance: '0.00',
      },
    };
  },
  async created() {
    //console.log('test666');
    this._getWallet();
  },
  methods: {
    //路由跳转
    goTo(url) {
      this.$Router.push({
        name: url,
      });
    },
    //获取钱包数据
    async _getWallet() {
      const { code, data } = await getWalletInfo();
      if (code != 200) return;
      this.isLoading = false;
      //console.log(data);
      this.userData = data;
    },
    //前往提现页面
    async goToCash(url) {
      const { code, data, msg } = await withdrawalCheck();
      //判断一下返回码如果是901则跳转设置提现账户页面
      if (code == 901) {
        uni.$u.toast(msg);
        setTimeout(() => {
          this.$Router.push({
            name: 'cash-account',
          });
        }, 800);
      }
      if (code != 200) return;
      this.$Router.push({
        name: url,
        params: {
          number: this.userData.accountBalance,
        },
      });
    },
  },
};
</script>

<style>
page {
  background: #f2f2f2;
}
</style>
